package com.ht.demo.admin.controller.system;

import com.ht.demo.common.appexception.AppException;
import com.ht.demo.common.appexception.ResultData;
import com.ht.demo.common.pojo.bo.system.SysUserBO;
import com.ht.demo.common.pojo.vo.LoginBodyVO;
import com.ht.demo.common.constans.SystemConstant;
import com.ht.demo.service.manager.system.SysUserManager;
import com.ht.demo.service.system.UserTokenManager;
import com.ht.demo.service.util.ServletUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author hdengxian
 * @Date 2023/3/28 13:08
 */
@RestController
@RequestMapping("${basePath}")
public class LoginController {
    @Resource
    private UserTokenManager userTokenManager;
    @Resource
    private SysUserManager sysUserManager;

    @PostMapping("/login")
    public ResultData<SysUserBO> userLogin(@RequestBody LoginBodyVO loginBodyVO) throws AppException {
        SysUserBO data = userTokenManager.userLogin(loginBodyVO);
        return new ResultData<>(data);
    }

    @PostMapping("/logout")
    public ResultData<Boolean> userExitLogin() throws AppException {
        String token = ServletUtils.getRequest().getHeader(SystemConstant.TOKEN_NAME);

        return new ResultData<>(userTokenManager.userExitLogin(token));
    }

    @GetMapping("/getInfo")
    public ResultData getInfo() throws AppException{
       return sysUserManager.getInfo();
    }


}
